package com.wanghlme.bookstore.util;

import com.wanghlme.bookstore.bean.Cart;
import com.wanghlme.bookstore.bean.CartItem;

import java.util.Map;

public class CartUtil {
    public static int getTotalCount(Map<String, CartItem> map) {
        if (map == null) {
            return -1;
        }
        int totalCount = 0;
        for (CartItem tmp : map.values()) {
            totalCount += tmp.getCount();
        }
        return totalCount;
    }

    public static double getTotalPrice(Map<String, CartItem> map) {
        if (map == null) {
            return -1;
        }
        double totalPrice = 0;
        for (CartItem tmp : map.values()) {
            totalPrice += tmp.getPrice();
        }
        return totalPrice;
    }
}
